//
//  NSArray+NSArray_SortByPinYin.m
//  Fengshui
//
//  Created by huliang on 13-5-28.
//
//

#import "NSArray+NSArray_SortByPinYin.h"

@implementation NSArray (NSArray_SortByPinYin)



//按照拼音排序
//处理后的数组，排序好，并且第一个字母带拼音的第一个字母
-(id)sortByPinYin{
    
    NSMutableArray *keyProcessed = [[NSMutableArray alloc] initWithCapacity:[self count]];
    
    //处理key,得到第一个汉子的拼音
    for(NSString *k in self){
        NSString *tmpChar =  [NSString stringWithFormat:@"%c",pinyinFirstLetter([k characterAtIndex:0])];
        [keyProcessed addObject:[NSString stringWithFormat:@"%@%@",tmpChar,k]];
    }
    NSArray *sortedArrayKey = [keyProcessed sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1 compare:obj2 options:NSNumericSearch];
    }];
    /*
     NSMutableArray *sortedArrayKeyFinal = [[NSMutableArray alloc] initWithCapacity:[sortedArrayKey count]];
     for(NSString *s in sortedArrayKey){
     [sortedArrayKeyFinal addObject:[s substringFromIndex:1]];//去掉汉字中加入的辅助字母
     }
     */
//    [keyProcessed release];

    return sortedArrayKey;
}

@end
